export * from './config'
export * from './env'
export * from './log'
export * from './fs'

const isType = (params: unknown, type: string) => {
  return Object.prototype.toString.call(params) === `[object ${type}]`
}

export const isObject = (params: unknown): params is object => {
  return isType(params, 'Object')
}


export function deepClone(obj: any, cache = new WeakMap()) {
  if (obj === null) return obj;
  if (typeof obj !== "object") return obj;
  if (cache.get(obj)) return cache.get(obj);
  if (obj.constructor === Date) {
    return new Date(obj);
  }
  if (obj.constructor === RegExp) {
    return new RegExp(obj.source, obj.flags);
  }
  const res = new obj.constructor();
  Object.keys(obj).forEach((key) => {
    const val = obj[key];
    res[key] = deepClone(val, cache);
  });

  cache.set(obj, res)

  return res;
}
